const {
    API_message_200,
    API_message_500,
} = require("../app/constants/messageAPI");
const UserService = require("../service/user.service");

class UserController {
    //创建用户
    async createUser(ctx, next) {
        const user = ctx.request.body;
        // console.log(user);
        //调用数据库
        const res = await UserService.create(user);

        if (res) {
            //获取用户信息
            const [userInfo] = await UserService.getUserByName(user.username);

            // 创建用户基本信息
            const create_userInfo = await UserService.createUserInformation(userInfo);

            //查询用户基本信息
            const [createdInfo] = await UserService.getUserInformationById(userInfo.id);
            ctx.body = API_message_200(createdInfo, "注册成功");
        } else {
            ctx.body = API_message_500("注册失败");
        }
    }
}

module.exports = new UserController();
